<template>
  <div>
    <h2>axios 全局配置</h2>
    <button @click="getInfo">get 请求</button>
    <button @click="postInfo">post 请求</button>
  </div>
</template>

<script>
// import axios from "axios";
export default {
  name: "AxiosDemo",
  components: {},
  data() {
    return {};
  },
  beforeCreate() {},
  created() {},
  beforeMount() {},
  mounted() {
    // var test = axios.get(" https://www.escook.cn/api/finduser/zs");
    // console.log("test:", test);
  },
  beforeUpdate() {},
  updated() {},
  activated() {},
  computed: {},
  watch: {},
  methods: {
    /* 
        使用全局导入的axios进行get请求
      */
    async getInfo() {
      let { data: res } = await this.$http.get("/api/finduser/zs");
      console.log("get data:", res);
    },
    /* 
        使用全局导入的axios进行post请求
      */
    async postInfo() {
      let { data: res } = await this.$http.post("/api/post", { name: "zs", age: 20 });
      console.log("post data:", res);
    },
  },
  beforeUnmount() {},
  unmounted() {},
};
</script>
<style scoped></style>
